package com.ryskoo.controller.basicdata;

import java.util.List;
import com.ryskoo.basicdata.logo.domain.LogoPO;
import com.ryskoo.basicdata.logo.service.ILogoService;
import com.ryskoo.framework.core.bean.ReturnMessageDTO;
import com.ryskoo.framework.core.controller.BasicHandler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * logo设置
 * @author BeHappy
 */
@Controller
@RequestMapping("/vendor/basicdata/logo")
public class LogoController extends BasicHandler<LogoPO> {
    private static final String TEMPLATE_PATH = "system/basicdata/logo";

    private static final String MODULE_NAME = "Logo";

    private ILogoService logoService;
    /**
     * 基类构造方法.
     */
    public LogoController() {
        super(TEMPLATE_PATH, MODULE_NAME);
    }

    /**
     * 消费者注入
     *
     * @param logoConsumer 消费者基类
     */
    @Autowired
    protected void setService(ILogoService logoService) {
        this.logoService = logoService;
        super.setService(logoService);
    }

    /**
     * 跳转列表页
     *
     * @return 页面模板路径
     */
    @GetMapping("/tosetting")
    public String toSetting(Model model, HttpServletRequest request) {
    	LogoPO po = null;
    	List<LogoPO> logos = logoService.getAll();
    	if (logos != null && logos.size() > 0) {
    		po = logoService.getAll().get(0);
    	}
        model.addAttribute("dto", po);
        return TEMPLATE_PATH + "/" + MODULE_NAME + "Setting";
    }

    /**
     * 编辑
     *
     * @param dto
     *            编辑的对象 {@link LogoDTO}
     * @return 统一返回消息 {@link ReturnMessageDTO}
     */
    @PostMapping("/setting")
    @ResponseBody
    public ReturnMessageDTO setting(@RequestBody LogoPO dto) {
        return super.edit(dto);
    }
}
